package com.evil.application.pojo.dto.es;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyang
 * @date 2023-08-08 15:48
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class AggRev extends Agg {

    public AggRev(String title) {
        super(title);
    }

    @Override
    public Aggregation.Builder.ContainerBuilder toAggregation() {
        return new Aggregation.Builder().reverseNested(e -> e);
    }

    @Override
    public String toString() {
        HashMap<Object, Object> map = new HashMap<>();
        Map<String, Object> objMap = BeanUtil.beanToMap(this, true, false);
        map.put(this.getTitle(), objMap);
        return JSONUtil.toJsonStr(map);
    }
}
